package com.systech.core.ibatis;

import java.io.FileInputStream;
import java.io.Reader;
import java.util.Properties;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class InitIbatis {

	private static SqlSessionFactory factory;
	
	public InitIbatis(String props) throws Exception {

		String resource = "META-INF/ibatis.xml";
		Reader reader = Resources.getResourceAsReader(resource);
		
		Properties properties = new Properties();
		properties.load(new FileInputStream(props));
		
		factory = new SqlSessionFactoryBuilder().build(reader, properties);
		
	}
	
	public SqlSessionFactory getFactory(){
		return factory;
	}
	
	public static SqlSession createSession() throws Exception{
		
		return factory.openSession();
		
	}
}
